﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Blazing.WebShop.Classes;
using Blazing.WebFacade;

namespace Blazing.WebShop
{
    public partial class Category : SiteBasePage
    {
        public UrlFragmentParser parser = null;

        public string QueryPath
        {
            get
            {
                return Request.QueryString["path"];
            }
        }

        public override string PagePath
        {
            get
            {
                return "/category/";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            parser = new UrlFragmentParser(QueryPath);

            var controller = new ProductsController();
            var products = controller.GetProductsByTag(parser.OrderedTaxonomyTags);

            var listWithUrl = from p in products 
                       select new { ID = p.ID, Name = p.Name, Price = p.Price,
                       Url = controller.GetProductHomepage(p, _site), ProductItem = p };

            var list = from p in listWithUrl.ToList()
                       where p.Url != null
                       orderby p.Name
                       select p;

            GridViewProducts.DataSource = list;
            GridViewProducts.DataBind();

            RepeaterTags.DataSource = parser.OrderedTaxonomyTags;
            RepeaterTags.DataBind();
        }
    }
}
